package com.lagou.edu.service.impl;

import com.lagou.edu.annotation.MyAutowired;
import com.lagou.edu.annotation.MyService;
import com.lagou.edu.annotation.MyTransactional;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * @author 应癫
 */
@MyTransactional
@MyService
public class TransferServiceImpl implements TransferService {

    // 【直播视频要求】属性使用Qualifier限定名称的场合
    @MyAutowired
    @Qualifier("accountDao")
    private AccountDao dao;

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

        Account from = dao.queryAccountByCardNo(fromCardNo);
        Account to = dao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        dao.updateAccountByCardNo(to);
//        int c = 1/0;
        dao.updateAccountByCardNo(from);
    }
}
